<?php session_start();
require('globals/setup.php');
$smarty = new Smarty_Kalender;	

$host  = $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_NAME'] == 'localhost'){$uri= URI_L;}else{$uri= URI_P;}
if (!isset($_SESSION['id_user']) || $_SESSION['id_user']=='') {
	echo "<script language=Javascript> location.href='http://$host$uri/index.php'; </script>";	
}else{
	
	if (!is_object($bd)){	
		require("globals/Db.class.php");
		require("globals/Conf.class.php");
		$bd=Db::getInstance();
	}
	if (!is_object($util)){	
		include("globals/Util.class.php");
		$util=Util::getInstance();
	}
		
	$util->debugOn();
	
	if (!($util->administrarTiempoSesion())){
		echo "<script language=Javascript> location.href='http://$host$uri/timeout.php'; </script>";
	}else if (!($util->administrarAcceso("facturacion"))){
		echo "<script language=Javascript> location.href='http://$host$uri/sinAcceso.php'; </script>";
	}
	
	$idFac = $_GET["fid"];
	
	$query = "select * from facturas where id = $idFac";
	$result1 = $bd->eje($query);
	$row = $bd->fila($result1);
	$idOT = $row["id_ot"];
	
	$smarty->assign("idFac", $idFac);
	$smarty->assign("idOT", $idOT);
	$smarty->assign("numero_fac", $row["numero"]);
	$smarty->assign("estado_fac", $util->decodeFACStatus($row["estado"]));
	$smarty->assign("enableEdit", ($row["estado"]=='E'));
	$smarty->assign("razon_social", $util->getRazonSocialFromThisOT($bd, $idOT));
	$smarty->assign("total", $util->getTotalAmountFromThisOT($bd, $idOT));
	
	$array_resultado = $util->getAllElementsWithValuesForThisOT($bd, $idOT);
	$smarty->assign("array_resultado", $array_resultado);
	
				
	$id_user = $_SESSION['id_user'];	
	
	$menuItem = "facturacion";
	$smarty->assign("menuItem", $menuItem);
	include("globals/menuIzquierda.php");
	$smarty->display("edicionFac.tpl");

} //del if grande 
?>